package BiShi.first.wangyi;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main4 {
    public static void main(String[] args) {
        //System.out.println(helper(0,0));
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int n = sc.nextInt();
            int m = sc.nextInt();
            int[][] arr = new int[n][m];
            sc.nextLine();
            for(int i = 0 ; i < n ; i++){
                String s = sc.nextLine();
                arr[i] = new int[m];
                char[] c = s.toCharArray();
                for(int j = 0 ; j < m; j++){
                    arr[i][j] = c[j] - '0';
                }
            }

            int[][] ans = new int[n][m];
            for(int i = 0 ; i < n ; i++){
                for(int j = 0 ; j < m; j++){
                    ans[i][j] = helper(arr, i ,j);
                }
            }
            for(int i = 0 ; i < n ; i++){
                for(int j = 0 ; j < m; j++){
                    if(arr[i][j]==0){
                        System.out.print(0);
                    }else{
                        System.out.print(ans[i][j]);
                    }

                    if(j != arr.length-1){
                        System.out.print(" ");
                    }
                }
                System.out.println("");
            }
        }
    }

    private static int helper(int[][] arr, int i, int j) {
        int res = 2 * arr.length -1 ;
        if(i>0 && arr[i-1][j]==0 || j>0 && arr[i][j-1]==0 ){
            res = 1;
            return res;
        }
        if(i < arr.length-1 && arr[i+1][j]==0 || j < arr[0].length -1 && arr[i][j+1]==0 ){
            res = 1;
            return res;
        }
            if(i>0){
                res = Math.min(res, 1 + helper(arr, i-1 ,j));
            }
            if(i < arr.length-1){
                res = Math.min(res, 1 + helper(arr, i+1 ,j));
            }
            if(j>0){
                res = Math.min(res, 1 + helper(arr, i ,j-1));
            }
            if(j < arr[0].length-1){
                res = Math.min(res, 1 + helper(arr, i ,j+1));
            }

        return res;
    }






}